package com.earthchen.demo.controller;

import com.earthchen.core.base.BaseController;
import com.earthchen.core.support.quartz.domain.TaskScheduled;
import com.earthchen.core.support.quartz.service.SchedulerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * quartz 测试控制器
 *
 * @author earthchen
 * @date 2018/9/2
 **/
//@RestController
//@RequestMapping("/quartz")
public class QuartzController extends BaseController {

    @Autowired
    private SchedulerService schedulerService;


    @GetMapping("/create")
    public Object create() {
        TaskScheduled taskScheduled = new TaskScheduled();
        taskScheduled.setTaskName("test1");
        taskScheduled.setJobType(TaskScheduled.JobType.job);
        taskScheduled.setTaskType(TaskScheduled.TaskType.local);
        taskScheduled.setTaskCron("0/1 * * * * ?");
        taskScheduled.setTaskGroup("test");
        taskScheduled.setStatus("1");
        taskScheduled.setTargetObject("printService");
        taskScheduled.setTargetMethod("print");
        taskScheduled.setTaskDesc("测试描述");
        schedulerService.updateTask(taskScheduled);
        return SUCCESS;
    }


    @GetMapping("/close")
    public Object close() {
        TaskScheduled taskScheduled = new TaskScheduled();
        taskScheduled.setTaskName("test1");
        taskScheduled.setTaskGroup("test");
        schedulerService.closeTask(taskScheduled);
        return SUCCESS;
    }


    @GetMapping("/open")
    public Object open() {
        TaskScheduled taskScheduled = new TaskScheduled();
        taskScheduled.setTaskName("test1");
        taskScheduled.setTaskGroup("test");
        schedulerService.openTask(taskScheduled);
        return SUCCESS;
    }


}
